using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class InGameUI : MonoBehaviour
{
    public GameObject player;
    private Character character;
    private CharacterStats stats;
    private PlayerStats playerStats;

    public Slider HPSlider;
    public Slider delightSlider;
    public Slider rageSlider;
    public Slider griefSlider;
    public Slider fearSlider;

    [SerializeField] private TextMeshProUGUI EXPText;
    [SerializeField] private float EXPAmount;
    [SerializeField] private float EXPAmountIncreaseRate = 100;

    public Dictionary<EmotionType, Slider> emotionSliderDic;

    private void Start()
    {
        character = player.GetComponent<Character>();
        playerStats = player.GetComponent<PlayerStats>();
        stats = player.GetComponent<CharacterStats>();

        emotionSliderDic = new Dictionary<EmotionType, Slider>();

        emotionSliderDic[EmotionType.Delight] = delightSlider;
        emotionSliderDic[EmotionType.Rage] = rageSlider;
        emotionSliderDic[EmotionType.Grief] = griefSlider;
        emotionSliderDic[EmotionType.Fear] = fearSlider;

        //����UI�仯ί��
        stats.onHealthChanged += UpdataHPUI;
        playerStats.onEmotionChanged += UpdateEmotionUI;
    }

    private void Update()
    {
        if (EXPAmount < PlayerManager.instance.EXP)
        {
            EXPAmount += Time.deltaTime * EXPAmountIncreaseRate;
        }
        else
            EXPAmount = PlayerManager.instance.EXP;

        EXPText.text = ((int)EXPAmount).ToString();
    }

    #region UpdateUI
    private void UpdataHPUI()
    {
        HPSlider.maxValue = stats.GetFinalMaxHP();
        HPSlider.value = stats.currentHP;
    }

    private void UpdateEmotionUI()
    {
        ItemData_Weapon weapon = PlayerManager.instance.player.currentWeapon;
        EmotionType emotionType = weapon.emotionType;

        emotionSliderDic[emotionType].maxValue = playerStats.maxEmotionValueDic[emotionType].GetValue();
        emotionSliderDic[emotionType].value = playerStats.currentEmotionValueDic[emotionType];
    }

    //private void UpdataDelightUI()      //����ϲ����ʾ
    //{
    //    delightSlider.maxValue = stats.maxDelight.GetValue();
    //    delightSlider.value = playerStats.currentDelight;
    //}

    //private void UpdateRageUI()         //���·�ŭ��ʾ
    //{
    //    rageSlider.maxValue = stats.maxRage.GetValue();
    //    rageSlider .value = playerStats.currentRage;
    //}

    //private void UpdateGriefUI()        //���°�����ʾ
    //{
    //    griefSlider.maxValue = stats.maxGrief.GetValue();
    //    griefSlider .value = playerStats.currentGrief;
    //}

    //private void UpdateFearUI()         //���¿־���ʾ
    //{
    //    fearSlider.maxValue = stats.maxFear.GetValue();
    //    fearSlider .value = playerStats.currentFear;
    //}

    private void OnDisable()
    {
        stats.onHealthChanged -= UpdataHPUI;
        //playerStats.onDelightChanged -= UpdataDelightUI;
        //playerStats.onRageChanged -= UpdateRageUI;
        //playerStats.onGriefChanged -= UpdateGriefUI;
        //playerStats.onFearChanged -= UpdateFearUI;

        playerStats.onEmotionChanged -= UpdateEmotionUI;
    }

    #endregion
}
